
#ifndef __SAKCAB_CU_INDEX_HPP_2010__
#define __SAKCAB_CU_INDEX_HPP_2010__

#include <string>

#include "bocat/common/lrucache.hpp"

#include "recloc.hpp"

namespace   sakcab   {

#define DEFAULT_RCNUM  (1024 * 1024 * 2)
#define DEFAULT_HASH_BNUM   (1024 * 1024 * 1)
#define DEFAULT_TREE_BNUM   (1024 * 1024 * 1)


class	CuKCAIndex
{
public  :

    virtual int put( const std::string& skey,
                     const std::string& data ) = 0;

    virtual int get( const std::string& skey,
                           std::string& data ) = 0;

    virtual int erase( const std::string& skey ) = 0;


public	:
	
	virtual	int	optimize( void ) = 0;

	virtual	int	snapshot( const char* snap_filename, const char* key_encode=NULL, const char* value_encode=NULL ) = 0;

public	:
	virtual	~CuKCAIndex() {}
};	//// class CuKCAIndex


class   CuIndex
{

	typedef	CuKCAIndex *	dbp_type;
	//typedef	bocat::common::LRUCache< std::string, dbp_type >	dbp_cache_type;

    #define DEFAULT_N_CACHE_TABLES  64
    #define SECTION_NAME    "sakcab::index"

public	:
	CuIndex( const char* ini_filename, const char* ini_section );
	~CuIndex();

public  :

    int put( const std::string& skey,
             const std::string& data );

    int get( const std::string& skey,
                   std::string& data );

    int erase( const std::string& skey );

public	:

	int	optimize( void );

	int	snapshot( const char* snap_filename, const char* key_encode=NULL, const char* value_encode=NULL );

private :
    void parseConfigure( const char* ini_filename, const char* ini_section );

private	:
	dbp_type	_db_p;

private	:

	//dbp_cache_type	_dbp_cache;
	//boost::mutex	_dbp_cache_mutex;

	//dbp_type	openTable( const std::string& table_name );
	//void		closeAllTables();

    std::string _db_home;

    std::string _engine;
};  //// class CuIndex


}   //// namespace sakcab


#endif  //// __SAKCAB_CU_INDEX_HPP_2010__


